package com.hsd.survey.action;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsd.core.page.entity.PageParams;
import com.hsd.core.page.entity.Pagination;
import com.hsd.survey.service.ISurveyCommonService;

/**
 * <p>
 * 类描述：问卷数据管理
 * <p>
 * 创建人：Abdi
 * <p>
 * 创建时间：2013-11-3 下午07:10:49
 */
@Controller
@RequestMapping("/data")
public class SurveyDataAction {
	@Autowired
	private ISurveyCommonService commonService;
	
	/**
	 * 数据管理 ：加载调研信息列表
	 * @param pageParams
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/loadResearchList.do")
	public String loadResearchList(PageParams pageParams,HttpServletRequest request,ModelMap model){
		String surveyname = request.getParameter("surveyname");
		String answername = request.getParameter("answername");
		Pagination page = commonService.loadResearchList(pageParams,surveyname,answername);
		
		model.addAttribute("page",page);
		model.addAttribute("surveyname",surveyname);
		model.addAttribute("answername",answername);
		return "app/data/data-research-list";
	}
	
	/**
	 * 健康监测、数据管理：查看调研信息；参数传递
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/viewResearch.do")
	public String viewResearch(HttpServletRequest request,ModelMap model){
		String surveyuuid = request.getParameter("surveyuuid");
		String researchuuid = request.getParameter("researchuuid");
		
		model.put("surveyuuid", surveyuuid);
		model.put("researchuuid", researchuuid);
		return "app/survey/data/data-survey-info";
	}
	
	/**
	 * 健康监测： 加载调研答题情况
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/loadPageData.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String loadPageData(HttpServletRequest request,ModelMap model){
		String surveyuuid = request.getParameter("surveyuuid");
		String researchuuid = request.getParameter("researchuuid");
		System.out.println(researchuuid + "============================" + surveyuuid);
		String pageData = commonService.loadSurveyData(surveyuuid,researchuuid,true).toString();
		return pageData;
	}
}